home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14232 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: ix.netcom.com!news
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Derivation and calling virtual functions
  5. Date: Fri, 29 Mar 1996 13:19:16 GMT
  6. Organization: Netcom
  7. Message-ID: <315be2ff.257321608@nntp.ix.netcom.com>
  8. References: <graphix.828032689@spiff.cc.iastate.edu>
  9. NNTP-Posting-Host: ix-dc11-06.ix.netcom.com
  10. X-NETCOM-Date: Fri Mar 29  7:16:11 AM CST 1996
  11. X-Newsreader: Forte Agent .99d/32.182
  12.  
  13. graphix@iastate.edu (Kent A Vander Velden) wrote:
  14.  
  15. >   Say we have the following:
  16. > class Base {
  17. > public:
  18. >   virtual void func() { // some stuff }
  19. >   virtual void write() { func(); };
  20. > };
  21. > class Derived : public Base {
  22. > public:
  23. >   void func() { // some stuff }
  24. >   write(); { Base::func(); }
  25. > };
  26. > Derived inst;
  27. >   Now, when I call inst.write() it in turn calls Bass::write() which in
  28. > turn calls Base::func().  Is there a way to instead have it call
  29. > Derived::func() if the instance is of type Derived?  I hoped the 
  30. > virtual keyword would help in this case.
  31.  
  32. The virtual keyword should do it.  This is it's purpose.
  33.  
  34.  
  35. Michael M Rubenstein
  36.